package com.dshore.messagecenter.service.warning.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dshore.messagecenter.dao.warning.WarningIndicatorsDao;
import com.dshore.messagecenter.model.system.ResponseResult;
import com.dshore.messagecenter.model.system.SysDict;
import com.dshore.messagecenter.service.warning.WarningIndicatorsService;
import com.dshore.messagecenter.util.Page;
import com.dshore.messagecenter.util.UUIDUtil;

@Service
public class WarningIndicatorsServiceImpl implements WarningIndicatorsService{

	@Autowired 
	private WarningIndicatorsDao warningIndicatorsDao;
	
	public Page<SysDict> getWarningIndicators(SysDict sysDict) {
		// 总记录数
				long total = warningIndicatorsDao.queryCountByPrama(sysDict);
				// 模糊查询
				List<SysDict> list = warningIndicatorsDao.queryListByPrama(sysDict);
				// 重构对象,方便扩展
				Page<SysDict> page = new Page<SysDict>(sysDict.getLimit(), total, sysDict.getOffset(),
						list);
				return page;
	}
	/**
	 * 展示单个数据
	 */
	@Override
	public SysDict getById(String id) {
		
		return warningIndicatorsDao.getById(id);
	}
	/**
	 * 删除
	 */
	@Override
	public ResponseResult<Void> deleteByIds(String ids) {
		ResponseResult<Void> responseResult =new ResponseResult<Void>(200,"删除成功");
		String[] id = ids.split(",");
		warningIndicatorsDao.deleteByIds(id);
		return responseResult;
	}
	/**
	 * 新增
	 */
	@Override
	public ResponseResult<Void> addIndicators(SysDict sysDict) {
		ResponseResult<Void>responseResult=new ResponseResult<Void>(200, "新增成功");
		Integer n = warningIndicatorsDao.selectMaxSeq();
		String code=warningIndicatorsDao.selectMaxCode(n);
		if(code!=null) {
			int m=9999+n;
			try {
				 m = Integer.parseInt(code);
			}catch(Exception e) {
				
			}finally {
				m+=1;
				sysDict.setDictCode(m+"");
			}
		}
		sysDict.setId(UUIDUtil.getUUId());
		sysDict.setSeq(n+1);		
		Integer i=warningIndicatorsDao.addIndicators(sysDict);
		if(i<=0) {
			responseResult.setState(400);
			responseResult.setMessage("新增失败");
		}
		return responseResult;
	}
	/**
	 * 修改
	 */
	@Override
	public ResponseResult<Void> changeIndicators(SysDict sysDict) {
		ResponseResult<Void>responseResult=new ResponseResult<Void>(200, "修改成功");
		Integer i=warningIndicatorsDao.changeIndicators(sysDict);
		if(i<0) {
			responseResult.setState(400);
			responseResult.setMessage("修改失败");
		}
		return responseResult;
	}
	/**
	 * 校验
	 */
	@Override
	public String checkIndicators(String id, String indicators1) {
		List<SysDict> list = warningIndicatorsDao.checkIndicators(indicators1);
		if(list.size()>0) {
			if(list.get(0).getId().equals(id)) {
				return "true";
			}else {
				return "false";
			}	
		}else {
			return "true";
		}		
	}
	
	
}
